Page({
  data: {
      username: '',
      password: ''
  },
  onUsernameInput(e) {
      this.setData({
          username: e.detail.value
      });
  },
  onPasswordInput(e) {
      this.setData({
          password: e.detail.value
      });
  },
  register(){
    wx.navigateTo({
      url: '/pages/my/login/Register/register'
      })
  },
  onLogin() {
      const that = this.data;
      const apiUrl = 'http://localhost:8080/user/login'; 
      wx.request({
          url: apiUrl,
          method: 'GET',
          data: {
            userUserName:that.username,
            userPassword:that.password
          },
          success: (res) => {
              if (res.data.code === 1) { 
                  // 保存用户信息到本地存储
                  wx.setStorageSync('userInfo', res.data.data); 
                  wx.showToast({
                      title: '登录成功',
                      icon: 'success',
                      success: () => {
                        setTimeout(() => {
                            wx.reLaunch({
                                url: '/pages/my/my'
                            });
                        }, 1000);
                    }
                  });
                 
              } else {
                  wx.showToast({
                      title: '用户名或密码错误',
                      icon: 'none'
                  });
              }
          },
          fail: () => {
              wx.showToast({
                  title: '网络请求失败',
                  icon: 'none'
              });
          }
      });
  }
});
  